package com.ftg.learn.chapter14;

import com.alibaba.fastjson2.JSON;

import java.util.List;

/**
 * fastjson2
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/3/7 下午3:03
 */
public class LearnJdbc06Fastjson {

    public static void main(String[] args) {
//        前后交互 json *.java json
//        *.java 与 *.java交互数据  List<pojo>
//         list<Map>  多表联表 (使用情况较少)
        LearnJdbc06Fastjson l = new LearnJdbc06Fastjson();
        String json = l.queryForFastJson(StudentPojo.class, "select * from student");

        System.out.println("-->"+json);
        String stu = "{\"sage\":23,\"sname\":\"张三\",\"sno\":\"s001\",\"ssex\":\"男\"}";
        StudentPojo studentPojo = JSON.parseObject(stu,StudentPojo.class);
        System.out.println(studentPojo.getSname());
    }

    public <T> String queryForFastJson(Class<T> c, String sql, Object... para) {
        LearnJdbc05 l = new LearnJdbc05();
        List<T> list = l.queryFoPojo1(c,sql,para);
        return JSON.toJSONString(list);
    }

}
